package com.ruoyi.web.zangchat.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.web.zangchat.domain.dto.ChatUsersRechargeDTO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.zangchat.domain.ChatUsersRecharge;
import com.ruoyi.web.zangchat.service.IChatUsersRechargeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户充值Controller
 * 
 * @author wudi
 * @date 2020-07-19
 */
@Controller
@RequestMapping("/zangchat/recharge")
public class ChatUsersRechargeController extends BaseController
{
    private String prefix = "zangchat/recharge";

    @Autowired
    private IChatUsersRechargeService chatUsersRechargeService;

    @RequiresPermissions("zangchat:recharge:view")
    @GetMapping()
    public String recharge()
    {
        return prefix + "/recharge";
    }

    /**
     * 查询用户充值列表
     */
    @RequiresPermissions("zangchat:recharge:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String,Object> map)
    {
        startPage();
        return getDataTable(chatUsersRechargeService.chatUsersRechargList(map));
    }

    /**
     * 导出用户充值列表
     */
    @RequiresPermissions("zangchat:recharge:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ChatUsersRecharge chatUsersRecharge)
    {
        List<ChatUsersRecharge> list = chatUsersRechargeService.list(new QueryWrapper<>());
        ExcelUtil<ChatUsersRecharge> util = new ExcelUtil<ChatUsersRecharge>(ChatUsersRecharge.class);
        return util.exportExcel(list, "recharge");
    }

    /**
     * 新增用户充值
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户充值
     */
    @RequiresPermissions("zangchat:recharge:add")
    @Log(title = "用户充值", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ChatUsersRecharge chatUsersRecharge)
    {
        return toAjax(chatUsersRechargeService.save(chatUsersRecharge));
    }

    /**
     * 修改用户充值
     */
    @GetMapping("/edit/{rechargeId}")
    public String edit(@PathVariable("rechargeId") Long rechargeId, ModelMap mmap)
    {
//        ChatUsersRecharge chatUsersRecharge = chatUsersRechargeService.getById(rechargeId);
        ChatUsersRechargeDTO chatUsersRechargeDTO = chatUsersRechargeService.selectChatUsersRechargDTOById(rechargeId);
        mmap.put("chatUsersRecharge", chatUsersRechargeDTO);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户充值
     */
    @RequiresPermissions("zangchat:recharge:edit")
    @Log(title = "用户充值", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ChatUsersRecharge chatUsersRecharge)
    {
//        return toAjax(chatUsersRechargeService.updateById(chatUsersRecharge));
        return chatUsersRechargeService.editSave(chatUsersRecharge);
    }

    /**
     * 删除用户充值
     */
    @RequiresPermissions("zangchat:recharge:remove")
    @Log(title = "用户充值", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(chatUsersRechargeService.removeByIds(Arrays.asList(Convert.toStrArray(ids))));
    }
}
